<template>
<!-- <el-dialog
    :close-on-click-modal="false"
    width="100%"
    height="100%"
    :visible.sync="visible">
        <el-form-item label="表名" prop="tableName">
      <el-input v-model="dataForm.tableName" placeholder="表名"></el-input>
    </el-form-item>
</el-dialog> -->

  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    width="100%"
    height="100%"
    :visible.sync="visible">
  <el-select v-model="value" clearable placeholder="请选择">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>

 <div></div>
 <el-tabs :tab-position="tabPosition" style="height: 200px;margin-top:20px">
    <el-tab-pane label="表一"></el-tab-pane>
    <el-tab-pane label="表二"></el-tab-pane>
    <el-tab-pane label="表三"></el-tab-pane>
    <el-tab-pane label="表四"></el-tab-pane>
  </el-tabs>


    <!-- <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="表名" prop="tableName">
      <el-input v-model="dataForm.tableName" placeholder="表名"></el-input>
    </el-form-item>
    <el-form-item label="表的列" prop="tableColumns">
      <el-input v-model="dataForm.tableColumns" placeholder="表的列"></el-input>
    </el-form-item>
    <el-form-item label="" prop="tableComment">
      <el-input v-model="dataForm.tableComment" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="业务包ID" prop="packageId">
      <el-input v-model="dataForm.packageId" placeholder="业务包ID"></el-input>
    </el-form-item>
    <el-form-item label="sql执行脚本" prop="sqlExcute">
      <el-input v-model="dataForm.sqlExcute" placeholder="sql执行脚本"></el-input>
    </el-form-item>
    <el-form-item label="0表示数据库表，1表示自主数据集" prop="type">
      <el-input v-model="dataForm.type" placeholder="0表示数据库表，1表示自主数据集"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span> -->
  </el-dialog>
</template>

<style>
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    line-height: 60px;
  }
  
  .el-aside {
    color: #333;
  }
</style>

<script>
  export default {
    data () {
       const item = {
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      };
      return {
        options: [{
          value: '1',
          label: '数据源一'
        }, {
          value: '2',
          label: '数据源二'
        }],
        value: '',
        tabPosition: 'left',
        visible: false,
        tableData: Array(20).fill(item),
        dataForm: {
          id: 0,
          tableName: '',
          tableColumns: '',
          tableComment: '',
          packageId: '',
          sqlExcute: '',
          type: ''
        },
        dataRule: {
          tableName: [
            { required: true, message: '表名不能为空', trigger: 'blur' }
          ],
          tableColumns: [
            { required: true, message: '表的列不能为空', trigger: 'blur' }
          ],
          tableComment: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          packageId: [
            { required: true, message: '业务包ID不能为空', trigger: 'blur' }
          ],
          sqlExcute: [
            { required: true, message: 'sql执行脚本不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '0表示数据库表，1表示自主数据集不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/report/businesstable/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.tableName = data.businessTable.tableName
                this.dataForm.tableColumns = data.businessTable.tableColumns
                this.dataForm.tableComment = data.businessTable.tableComment
                this.dataForm.packageId = data.businessTable.packageId
                this.dataForm.sqlExcute = data.businessTable.sqlExcute
                this.dataForm.type = data.businessTable.type
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/report/businesstable/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'tableName': this.dataForm.tableName,
                'tableColumns': this.dataForm.tableColumns,
                'tableComment': this.dataForm.tableComment,
                'packageId': this.dataForm.packageId,
                'sqlExcute': this.dataForm.sqlExcute,
                'type': this.dataForm.type
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
